package com.example.springcloud.service.impl;

import java.util.List;

import com.example.springcloud.mapper.UserScenicFavoriteMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.example.springcloud.mapper.ScenicSpotsMapper;
import com.example.springcloud.domain.ScenicSpots;
import com.example.springcloud.service.IScenicSpotsService;

/**
 * 景点信息Service业务层处理
 * 
 * @author helian
 * @date 2025-03-01
 */
@Service
public class ScenicSpotsServiceImpl implements IScenicSpotsService 
{
    @Autowired
    private ScenicSpotsMapper scenicSpotsMapper;

    @Autowired
    private UserScenicFavoriteMapper userScenicFavoriteMapper;

    /**
     * 查询景点信息
     * 
     * @param scenicId 景点信息主键
     * @return 景点信息
     */
    @Override
    public ScenicSpots selectScenicSpotsByScenicId(Long scenicId)
    {
        return scenicSpotsMapper.selectScenicSpotsByScenicId(scenicId);
    }

    /**
     * 查询景点信息列表
     * 
     * @param scenicSpots 景点信息
     * @return 景点信息
     */
    @Override
    public List<ScenicSpots> selectScenicSpotsList(ScenicSpots scenicSpots, Long userId)
    {
        List<ScenicSpots> scenicSpotsList = scenicSpotsMapper.selectScenicSpotsList(scenicSpots);
        // 该景点用户是否收藏
        for (ScenicSpots spot : scenicSpotsList) {
            if (userId != null) {
                if (userScenicFavoriteMapper.selectUserScenicFavoriteByScenicIdAndUserId(spot.getScenicId(), userId) != null){
                    spot.setLike(1);
                }else{
                    spot.setLike(0);
                }
            }
        }
        return scenicSpotsList;
    }

    /**
     * 新增景点信息
     * 
     * @param scenicSpots 景点信息
     * @return 结果
     */
    @Override
    public int insertScenicSpots(ScenicSpots scenicSpots)
    {
        return scenicSpotsMapper.insertScenicSpots(scenicSpots);
    }

    /**
     * 修改景点信息
     * 
     * @param scenicSpots 景点信息
     * @return 结果
     */
    @Override
    public int updateScenicSpots(ScenicSpots scenicSpots)
    {
        return scenicSpotsMapper.updateScenicSpots(scenicSpots);
    }

    /**
     * 批量删除景点信息
     * 
     * @param scenicIds 需要删除的景点信息主键
     * @return 结果
     */
    @Override
    public int deleteScenicSpotsByScenicIds(Long[] scenicIds)
    {
        return scenicSpotsMapper.deleteScenicSpotsByScenicIds(scenicIds);
    }

    /**
     * 删除景点信息信息
     * 
     * @param scenicId 景点信息主键
     * @return 结果
     */
    @Override
    public int deleteScenicSpotsByScenicId(Long scenicId)
    {
        return scenicSpotsMapper.deleteScenicSpotsByScenicId(scenicId);
    }
}
